﻿#include "langugemanage.h"
#include <QtDebug>
LangugeManage* LangugeManage::m_instance = nullptr;

LangugeManage::LangugeManage(QObject *parent) : QObject(parent),m_changeNofity("CN")
{
    m_translator = new QTranslator(this);
    m_translator->load(":/translations/qnote_"+m_changeNofity+".qm");
    qApp->installTranslator(m_translator);
}

LangugeManage::~LangugeManage()
{

}

QString LangugeManage::changeNofity()
{
    return m_changeNofity;

}

void LangugeManage::setchangeNofity(QString b)
{
    if(m_changeNofity != b)
    {
        m_changeNofity = b;
        emit changeNofityChanged();
    }
}

void LangugeManage::changeLanguage(QString lan)
{
    qApp->removeTranslator(m_translator);

    bool b = m_translator->load(":/translations/qnote_"+lan+".qm");

    if(b)
    {
        qApp->installTranslator(m_translator);
        setchangeNofity(lan);
    }
    else{
        qDebug()<<"load multiLanguage "<<"qnote_"+lan+".qm " << "error!!!";
    }
}
